package com.poorstu.dao.impl;

import java.util.List;

import com.common.base.dao.impl.BaseDaoImpl;
import com.common.base.model.PaginationSupport;
import com.poorstu.dao.RoleDao;
import com.poorstu.model.PowerMod;
import com.poorstu.model.RoleMod;

public class RoleDaoImpl extends BaseDaoImpl implements RoleDao{

	public boolean delRole(RoleMod role){
		try{
			super.delete(role);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return false;
			
		}
		return true;
	}

	public boolean delRoleList(List<RoleMod> roleList){
		try{
			super.deleteAll(roleList);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return false;
			
		}
		return true;
	}

	public boolean newRole(RoleMod role) {
		try{
			super.save(role);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return false;
			
		}
		return true;
	}

	public boolean updateRole(RoleMod role) {
		try{
			super.saveOrUpdate(role);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return false;
			
		}
		return true;
	}

	public PaginationSupport getRoleByPage(String where,
			String orderField, String order, Integer startIndex,
			Integer pageSize) {
		PaginationSupport ps;
		try{
			ps = super.findByWhereOrderBy(RoleMod.class.getName(), where, orderField, order, startIndex, pageSize);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return null;
			
		}
		return ps;
	}

	public RoleMod getRole(int id) {
		try{
			return (RoleMod)super.findByHql("from RoleMod where roleId = " + id).get(0);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return null;
			
		}
		
	}

	public List<RoleMod> selectRoleAll() {
		
		return super.findAll("RoleMod");
	}
	
	public List<PowerMod> getPowerAll() {
		try{
			return super.findByHql("from PowerMod where fratherId = 0");
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return null;
		}
	}
	
	
	


}
